Load the NY NOAA dataset

Scatter Plot: Precipitation vs Temperature

Bar Plot

Box Plot

---
title: "NY NOAA Weather Data Dashboard"
output: 
  flexdashboard::flex_dashboard:
    orientation: columns
    vertical_layout: fill
    source: embed
---

```{r setup, include=FALSE}
library(flexdashboard)
library(plotly)
library(p8105.datasets)
library(dplyr)
library(lubridate)
library(tidyr)
library(janitor)
```

# Load the NY NOAA dataset
```{r}
ny_noaa <- p8105.datasets::ny_noaa

ny_noaa_sample <- ny_noaa %>%
  filter(!is.na(tmax)) %>%
  sample_n(1000) 

```


### Scatter Plot: Precipitation vs Temperature

```{r}
plot_ly(data = ny_noaa_sample, x = ~tmax, y = ~prcp, type = 'scatter', mode = 'markers') %>%
  layout(title = "Scatterplot: Max Temperature vs Precipitation",
         xaxis = list(title = "Max Temperature (°C)"),
         yaxis = list(title = "Precipitation (mm)"))
```


### Bar Plot

```{r}

ny_noaa_sample <- ny_noaa_sample %>%
  mutate(
    tmax = as.numeric(tmax),    
    tmin = as.numeric(tmin),    
    month = month(date, label = TRUE) 
  ) %>%
  filter(!is.na(tmax))

ny_noaa_summary <- ny_noaa_sample %>%
  group_by(month) %>%
  summarize(avg_tmax = mean(tmax, na.rm = TRUE))

bar_plot <- plot_ly(ny_noaa_summary, x = ~month, y = ~avg_tmax, type = "bar", marker = list(color = "viridis")) %>%
  layout(
    title = "Average Maximum Temperature by Month",
    xaxis = list(title = "Month"),
    yaxis = list(title = "Average Max Temperature (°C)"),
    barmode = "group"
  )

bar_plot
```


### Box Plot
```{r}
library(forcats)

ny_noaa_sample %>%
  mutate(month = fct_reorder(month, tmax, .fun = median, na.rm = TRUE)) %>% 
  plot_ly(y = ~tmax, x = ~month, color = ~month, type = "box", colors = "viridis") %>%
  layout(
    title = "Monthly Distribution of Maximum Temperature",
    xaxis = list(title = "Month"),
    yaxis = list(title = "Maximum Temperature (°C)"))

```